package nil.ed.livechat.timeshift.sync;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import nil.ed.livechat.timeshift.sync.ext.PublishEventSubscriber;
import nil.ed.livechat.timeshift.sync.ext.RedisSyncService;
import nil.ed.livechat.timeshift.sync.guice.BaseModule;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author delin10
 * @since 2020/6/26
 **/
public class Main {

    private static int THREAD_COUNT = 5;

    private static Executor executor = new ThreadPoolExecutor(THREAD_COUNT, THREAD_COUNT, 5, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(100),
            (ThreadFactory) Thread::new);


    public static void main(String[] args) {
        Injector injector = Guice.createInjector(new BaseModule());
        List<Runnable> tasks = new LinkedList<>();
        PublishEventSubscriber subscriber = injector.getInstance(PublishEventSubscriber.class);
        RedisSyncService redisSyncService = injector.getInstance(RedisSyncService.class);
        for (int i = 0; i < THREAD_COUNT; ++i) {
            TsScheduledUpdateTask task = injector.getInstance(TsScheduledUpdateTask.class);
            tasks.add(task);
            executor.execute(task);
        }
       redisSyncService.startSubscribe();
    }

}
